/**
 * 
 */
package ca.abubakrsagar.breadboardsim;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JComponent;

/**
 * This class deals with the resistors. It extends JComponent.
 * 
 * @author Sagar, Abubkar
 * @since June 14, 2012
 */
public class Resistor extends Component {

	private int ohms; // the ohms of the resistor
	private int direction; // The direction of the resistor

	/**
	 * @param ohms
	 *            The ohms of the resistor
	 * @param direction
	 *            The direction of the resistor This is the constructor for the
	 *            resistor
	 */
	public Resistor(int ohms, int direction) {
		// initializes the resistor
		this.ohms = ohms;
		this.setPreferredSize(new Dimension(15, 15));
		this.setVisible(true);
		this.direction = direction;
		setComponentType(1);
	}

	/**
	 * @param g
	 *            The graphics object Draws the resistor on the screen
	 */
	public void paintComponent(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		if (this.direction == 1) {
			g.fillRect(0, 0, 6, 36);
		} else {
			g.fillRect(0, 0, 26, 6);
		}

	}

	/**
	 * @return ohms Returns the resistance value of the resistor.
	 */
	public int getOhms() {
		return this.ohms;
	}

	/**
	 * Sets the ohms of the resistor
	 * 
	 * @param ohms
	 *            The ohms of the resistor
	 */
	public void setOhms(int ohms) {
		this.ohms = ohms;
	}

	/**
	 * 
	 * @return The direction of the resistor.
	 */
	public int getDirection() {
		return direction;
	}

}
